﻿/// <reference path="../Ext4.0/ext-all.js" />
ImportInfos = function () {
   
    var ImportInfoForm = Ext.create('Ext.form.Panel', {
        width: 300,
        height: 100,
        plain: true,
        frame: true,
        labelWidth: 45,
        defaultType: "textfield",
        baseCls: "x-plain",
        layout: 'anchor',
        defaults: { anchor: "95%", msgTarget: "side" },
        url: "HotelRegMag.aspx?action=Import",
        bodyStyle: 'padding:5px 0px 0px 5px',
        // The fields
        defaultType: 'textfield',
        items: [{
            xtype: 'filefield',
            name: 'filePath',
            fieldLabel: '路徑',
            labelWidth: 50,
            msgTarget: 'side',
            allowBlank: false,
            anchor: '95%',
            buttonText: '請選擇文件'
        }],

        // Reset and Submit buttons
        buttonAlign: "center",

        buttons: [{
            text: '導入',
            formBind: true, //only enabled once the form is valid
            disabled: true,
            handler: function () {
                Ext.MessageBox.show({
                    msg: '正在导入数据，请稍后...',
                    progressText: 'Saving...',
                    width: 300,
                    wait: true,
                    waitConfig: { interval: 200 },
                    icon: 'ext-mb-download'
                });
                setTimeout(function () {
                    Ext.MessageBox.hide();
                }, 10000);
                var form = this.up('form').getForm();
                if (form.isValid()) {
                    form.submit({
                        success: function (form, action) {
                            Ext.MessageBox.hide();
                            Ext.Msg.alert("恭喜", "導入成功");
                            StorePage.load();
                            ImportWin.hide();
                        },
                        failure: function (form, action) {
                            Ext.Msg.alert('失败', action.result.msg);
                        }
                    });
                }
            }
        }]
    });

    var ImportWin = Ext.create('Ext.window.Window', {
        title: '導入',
        width: 320,
        height: 100,
        layout: 'fit',
        labelWidth: 100,
        closeAction: 'hide',
        resizable: false,
        modal: 'true',
        iconCls: "importicon",
        items: ImportInfoForm,
        listeners: {
            "show": function () {

            }
        }
    });
    ImportWin.show();
}


